home *** CD-ROM | disk | FTP | other *** search
- /* This program is called as follows
-
- a.out exit_value program_name arguments...
-
- exit_value is the value which the program will exit with
-
- program_name is the name of the child process to exec, with
- its arguments
- */
-
- #include <stdio.h>
- #include <signal.h>
-
- static int RET_VALUE;
- #define TRUE 1
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- RET_VALUE = atoi(argv[1]);
- argc -= 2;
- argv += 2;
- process(argc,argv);
- printf("Parent exiting with %d\n", RET_VALUE);
- exit(RET_VALUE);
- }
-
- process(argc,argv)
- int argc;
- char **argv;
- {
- int pid;
- int status;
- int ret;
- signal(SIGINT,SIG_IGN); /* Ignore interrupt key */
- pid = fork();
- if (pid == -1)
- {
- perror("all_true");
- exit(126);
- }
-
- if (pid > 0 )
- {
- printf("In parent, waiting for child\n");
- /* In parent */
- /* Wait for child */
- ret = wait(&status);รจ printf("Exit status from child is %x\n", status);
- if (ret == -1)
- perror("all_true");
- return;
- }
-
- /* In child */
- printf("Executing %s in child\n", argv[0]);
- signal(SIGINT, SIG_DFL);
- execvp(*argv, argv);
- perror("all_true");
- }
-
-
-
-